package com.alipay.sofa.award.common.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * DateFormatUtils
 *
 * @author yangguanchao
 * @since 2018/08/28
 */
public class DateFormatUtils {

    private static final String FORMAT_PATTERN = "yyyy-MM-dd HH:mm:ss";

    public static Date parseString(String datetime) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat(FORMAT_PATTERN);
        return format.parse(datetime);
    }

    public static String parseDate(Date date) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat(FORMAT_PATTERN);
        return format.format(date);
    }

    public static Date getEndTime() throws Exception {
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.set(Calendar.HOUR_OF_DAY, 23);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.SECOND, 59);
        todayEnd.set(Calendar.MILLISECOND, 999);
        return todayEnd.getTime();
    }
}
